import time

import Config
from tools import ActionUtil


class DailyTasks:
    def __init__(self, region):

        self.region = region

        self.mall_img = "images/mall.bmp"

        self.purchase_img = "images/purchase.bmp"

        self.back_img = "images/back.bmp"

        self.confirm_img = "images/confirm.bmp"

    @staticmethod
    def daily_main(region):
        if Config.do_daily:
            task = DailyTasks(region)
            # 免费复活币
            task.purchase_coin()

    def purchase_coin(self):
        _location = ActionUtil.find_icon(icon_path=self.mall_img, region=self.region)
        if _location:
            ActionUtil.mouse_left_click(_location)
            time.sleep(3)
            # 道具
            ActionUtil.mouse_left_click((100, 270))
            time.sleep(2)
            # 恢复品
            ActionUtil.mouse_left_click((430, 105))
            time.sleep(2)
            # 复活币
            ActionUtil.mouse_left_click((270, 190))
            time.sleep(2)
            # 购买
            _location = ActionUtil.find_icon(icon_path=self.purchase_img, region=self.region)
            if _location:
                ActionUtil.mouse_left_click(_location)
                time.sleep(3)
                # 确定
                _location = ActionUtil.find_icon(icon_path=self.confirm_img, region=self.region)
                if _location:
                    ActionUtil.mouse_left_click(_location)
                    time.sleep(2)
            # 返回
            _location = ActionUtil.find_icon(icon_path=self.back_img, region=self.region)
            if _location:
                ActionUtil.mouse_left_click(_location)
        return True


if __name__ == '__main__':
    daily_tasks = DailyTasks()
    daily_tasks.daily_main()
